/*****************************************************************************************************************
 *Header file for projects has nand as system disk only.
 *here we definate partition locatition as well as some macros may need by NAND driver
 ****************************************************************************************************************/
#ifndef ____DISK_NAND
#define ____DISK_NAND

#define CONFIG_NAND
#define CONFIG_NAND_IMAPX200

//#define CONFIG_YAFFS2
#define CONFIG_CMD_EXT2
#ifdef	CONFIG_ENV_IS_IN_SYS_DISK    
#define CONFIG_ENV_OFFSET               (0x0400000)     /* 4M */
#endif

#define CONFIG_PARTITION_START              (10)     /*9M*/

#ifdef  CONFIG_SYS_NAND_4G_SIZE
#define CONFIG_UDATA_PART_LEN               (1024)
#define CONFIG_SYS_DISK_END                 (4094)
#else
#define CONFIG_UDATA_PART_LEN               (512)
#define CONFIG_SYS_DISK_END                 (2047)
#endif //

#ifdef CONFIG_SYS_DISK_END
#define CONFIG_LOCAL_PART_LEN               (CONFIG_SYS_DISK_END-(CONFIG_PARTITION_START+CONFIG_RAMDISK_PART_LEN+\
			CONFIG_KERNEL_PART_LEN+CONFIG_CACHE_PART_LEN+CONFIG_SYSTEM_PART_LEN+ \
			CONFIG_MISC_PART_LEN+CONFIG_UDATA_PART_LEN))
#else
#error "Can not calculate local part capacity due to unavilable of capacity of system disk.\n"
#endif//CONFIG_SYS_DISK_END

/***********************From here we definite the start addr of each partition********************/
#define CONFIG_SYS_DISK_RD_OFFS		    (CONFIG_PARTITION_START<<20)
#define CONFIG_SYS_DISK_KERNEL_OFFS         (CONFIG_SYS_DISK_RD_OFFS+(CONFIG_RAMDISK_PART_LEN<<20))
#define CONFIG_SYS_DISK_SYSTEM_OFFS         (CONFIG_SYS_DISK_KERNEL_OFFS+(CONFIG_KERNEL_PART_LEN<<20))
#define CONFIG_SYS_DISK_UDATA_OFFS          (CONFIG_SYS_DISK_SYSTEM_OFFS+(CONFIG_SYSTEM_PART_LEN<<20))
#define CONFIG_SYS_DISK_CACHE_OFFS          (CONFIG_SYS_DISK_UDATA_OFFS+(CONFIG_UDATA_PART_LEN<<20))
#define CONFIG_SYS_DISK_MISC_OFFS           (CONFIG_SYS_DISK_CACHE_OFFS+(CONFIG_CACHE_PART_LEN<<20))
#define CONFIG_SYS_DISK_LOCAL_OFFS 	    (CONFIG_SYS_DISK_MISC_OFFS+(CONFIG_MISC_PART_LEN<<20))


#define CONFIG_SYS_DISK_LK1_OFFS            (CONFIG_SYS_DISK_KERNEL_OFFS)
#define CONFIG_SYS_DISK_RE_OFFS             (CONFIG_SYS_DISK_LK1_OFFS+0x0800000)
#define CONFIG_SYS_DISK_LK2_OFFS            (CONFIG_SYS_DISK_KERNEL_OFFS+0x1800000)
#define CONFIG_SYS_DISK_BOOTLG_OFFS	    (CONFIG_SYS_DISK_MISC_OFFS + 0x800000)
#define CONFIG_SYS_DISK_KERNLG_OFFS	    (CONFIG_SYS_DISK_MISC_OFFS + 0xC00000)

		/*******************************end of astart address difinition*****************************/

		/**************Here we fix the  max length a given image will ocuppy (unit MBytes)*****************/
#define CONFIG_SYS_LK_BURN_LEN                   (8<<20)
#define CONFIG_SYS_RD_BURN_LEN                  (2<<20)
#define CONFIG_SYS_RE_BURN_LEN                  (16<<20)
#define CONFIG_SYS_BOOTLG_BURN_LEN		(4 << 20)
#define CONFIG_SYS_KERNLG_BURN_LEN		(4 << 20)
#define CONFIG_SYS_SYSTEM_BURN_LEN              (CONFIG_SYSTEM_PART_LEN<<20)
#define CONFIG_SYS_UDATA_BURN_LEN               (CONFIG_UDATA_PART_LEN<<20)

#if (CONFIG_SYS_SYSTEM_LEN>CONFIG_SYSTEM_PART_LEN)
#error "Here will allow system image bigger than system partition capacity\n"
#endif
#define CONFIG_SYS_DISK_RELOC_OFFS      (0x02800000)    /* 40M */
#define CONFIG_SYS_DISK_BACK1_OFFS      (CONFIG_SYS_NAND_SYSTEM_OFFS)//(0x02800000) /* 168M */
#define CONFIG_SYS_DISK_BACK_LEN        (0x0c000000)    /* 128M */

/* NAND CHIP CFG */
#if defined(CONFIG_SYS_NAND_2K_PAGE)
#   define CONFIG_SYS_NAND_PAGE_SIZE    2048            /* Page size */
#   define CONFIG_SYS_NAND_BLOCK_SIZE   (128 * 1024)    /* Block size */
#   define CONFIG_SYS_NAND_PAGE_COUNT   64              /* Page per block */
#   define CONFIG_SYS_NAND_OOBSIZE      64              /* Size of OOB */
#   define CONFIG_SYS_NAND_DIRTYMARK    24              /* Dirty mark position */
#elif defined(CONFIG_SYS_NAND_4K_PAGE)
#   define CONFIG_SYS_NAND_PAGE_SIZE    4096
#   define CONFIG_SYS_NAND_BLOCK_SIZE   (512 * 1024)
#   define CONFIG_SYS_NAND_PAGE_COUNT   128
#   define CONFIG_SYS_NAND_OOBSIZE      128
#   define CONFIG_SYS_NAND_DIRTYMARK    44
#elif defined(CONFIG_SYS_NAND_8K_PAGE)
#   define CONFIG_SYS_NAND_PAGE_SIZE    8192
#if 1
#   define CONFIG_SYS_NAND_BLOCK_SIZE   (128 * 8192)
#   define CONFIG_SYS_NAND_PAGE_COUNT   128 
/* For H27UAG8T2BTR */
#else
#   define CONFIG_SYS_NAND_BLOCK_SIZE   (256 * 8192)
#   define CONFIG_SYS_NAND_PAGE_COUNT   256 
#endif
#   define CONFIG_SYS_NAND_OOBSIZE      436
#   define CONFIG_SYS_NAND_DIRTYMARK    280
#endif

#if defined(CONFIG_SYS_NAND_MLC)
#   define CONFIG_SYS_NAND_ECCSIZE      512             /* bytes ECC module can dealwith each time */
#   define CONFIG_SYS_NAND_ECCBYTES     9               /* bytes per eccsize */
#elif defined(CONFIG_SYS_NAND_SLC)
#   define CONFIG_SYS_NAND_ECCSIZE      2048
#   define CONFIG_SYS_NAND_ECCBYTES     8               /* Actually 4, but 8 bytes is used */
#else
#   error you must defined NAND cell type!
#endif
/* NAND DRV CFG */
#define CONFIG_SYS_MAX_NAND_DEVICE  1
#define CONFIG_SYS_NAND_BASE        0x20c50010      /* NFDATA */
#define CONFIG_SYS_NAND_5_ADDR_CYCLE                /* Extra address cycle for > 128MiB */
#define CONFIG_SYS_NAND_BAD_BLOCK_POS   0           /* Location of the bad-block label */
#define CONFIG_SYS_NAND_SDMA

#define CONFIG_SYS_NAND_ECCSTEPS    (CONFIG_SYS_NAND_PAGE_SIZE / CONFIG_SYS_NAND_ECCSIZE)
#define CONFIG_SYS_NAND_ECCTOTAL    (CONFIG_SYS_NAND_ECCBYTES * CONFIG_SYS_NAND_ECCSTEPS)
#define CONFIG_SYS_NAND_ECCPOS      {0};
#undef  CONFIG_SYS_NAND_BUSW16                      /* Turn on this is bus width is 16 */

#endif
/******************************************end of this file*******************************************************/
